package cn.mill.core.modem;

import java.lang.reflect.Type;

import cn.mill.common.Context;
import cn.mill.common.data.Item;

public class BooleanSpell implements FieldSpell {
	
	public static final BooleanSpell INSTANCE = new BooleanSpell();
	
	@Override
	public Item resolver(Context context, String name, Type type, Object object) {
		Item item = new Item();
		item.setName(name);
		item.setType(type);
		item.setValue(object);
		return item;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public <T> T builder(Type type, Item item) {
		Boolean b = new Boolean(false);
		if (item != null) {
			if ("1".equals(item.getValue()) || "true".equals(item.getValue())) {
				return (T) new Boolean(true);
			}
		}
		return (T) b;
	}
	
}
